/*
 * Copyright 2011 es-planning Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package jp.arctos.ursus.thread;

import javax.realtime.RealtimeThread;

/**
 * Thread controller class.
 *
 */
public class ThreadManager {
    
    /**
     * create thread.<br>
     * 
     * @param parameters RealtimeThreadParameters
     * @param logic create logic
     * @return created thread
     */
    public static Thread createThread(RealtimeThreadParameters parameters, Runnable logic) {
    	if (parameters != null) {
    		return createRealtimeThread(parameters, logic);
    	}
        return createJavaLangThread(logic);
    }
    
    /**
     * create javax.realtime.RealtimeThread.<br>
     * 
     * <p>if RealtimeThreadParameters is null, throws NullPointerException.</p>
     * 
     * @param parameters RealtimeThreadParameters
     * @param logic create logic
     * @return javax.realtime.RealtimeThread
     */
    public static RealtimeThread createRealtimeThread(RealtimeThreadParameters parameters, Runnable logic) {
        return new RealtimeThread(
                parameters.getSchedulingParameters(),
                parameters.getReleaseParameters(),
                parameters.getMemoryParameters(),
                parameters.getMemoryArea(),
                parameters.getProcessingGroupParameters(),
                logic);
    }
    
    /**
     * create java.lang.Thread.<br>
     * @param logic create logic
     * @return java.lang.Thread
     */
    public static Thread createJavaLangThread(Runnable logic) {
        return new Thread(logic);
    }
}
